< previous page page_541 next page >

Page 541
e10a6a0a59f035e870d90cca05b85fce.gif
      Do While Solids.Count > 0
         ' Find the face with the smallest Zmax
         ' left in the Faces collection.
         besti = 1
         bestz = Solids(1).ZMax
         For i = 2 To Solids.Count
             newz = Solids(i).ZMax
             If bestz > newz Then
                 besti = i
                 bestz = newz
             End If
         Next i

         ' Add the best object to the sorted list.
         ordered_solids.Add Solids(besti)
         Solids.Remove besti
    Loop

    ' Replace the Solids collection with the
    ' ordered_solids collection.
    Set Solids = ordered_solids
End Sub
Example program Depth1, shown in Figure 15.7, uses this method to draw scenes that contain convex solids. Use the option buttons to pick a scene to display. Use the Remove Backfaces check box to tell the program whether to hide the hidden surfaces.
Nonconvex Solids
Program Depth1 uses the Depth-Sort algorithm to draw convex solids in their proper order. To draw a nonconvex solid, you can use the same technique to draw the faces that make up the solid in their correct order.
0541-01.jpg
Figure 15.7
Program Depth1 uses backface removal and the Depth-
Sort algorithm to draw groups of convex solids.

 
< previous page page_541 next page >